package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RySalesRanking;
import com.ruoyi.pims.service.IRySalesRankingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售排行Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/ranking")
public class RySalesRankingController extends BaseController
{
    private String prefix = "pims/ranking";

    @Autowired
    private IRySalesRankingService rySalesRankingService;

    @RequiresPermissions("pims:ranking:view")
    @GetMapping()
    public String ranking()
    {
        return prefix + "/ranking";
    }

    /**
     * 查询销售排行列表
     */
    @RequiresPermissions("pims:ranking:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RySalesRanking rySalesRanking)
    {
        startPage();
        List<RySalesRanking> list = rySalesRankingService.selectRySalesRankingList(rySalesRanking);
        return getDataTable(list);
    }

    /**
     * 导出销售排行列表
     */
    @RequiresPermissions("pims:ranking:export")
    @Log(title = "销售排行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RySalesRanking rySalesRanking)
    {
        List<RySalesRanking> list = rySalesRankingService.selectRySalesRankingList(rySalesRanking);
        ExcelUtil<RySalesRanking> util = new ExcelUtil<RySalesRanking>(RySalesRanking.class);
        return util.exportExcel(list, "销售排行数据");
    }

    /**
     * 新增销售排行
     */
    @RequiresPermissions("pims:ranking:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售排行
     */
    @RequiresPermissions("pims:ranking:add")
    @Log(title = "销售排行", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RySalesRanking rySalesRanking)
    {
        return toAjax(rySalesRankingService.insertRySalesRanking(rySalesRanking));
    }

    /**
     * 修改销售排行
     */
    @RequiresPermissions("pims:ranking:edit")
    @GetMapping("/edit/{rankingId}")
    public String edit(@PathVariable("rankingId") Long rankingId, ModelMap mmap)
    {
        RySalesRanking rySalesRanking = rySalesRankingService.selectRySalesRankingByRankingId(rankingId);
        mmap.put("rySalesRanking", rySalesRanking);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售排行
     */
    @RequiresPermissions("pims:ranking:edit")
    @Log(title = "销售排行", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RySalesRanking rySalesRanking)
    {
        return toAjax(rySalesRankingService.updateRySalesRanking(rySalesRanking));
    }

    /**
     * 删除销售排行
     */
    @RequiresPermissions("pims:ranking:remove")
    @Log(title = "销售排行", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rySalesRankingService.deleteRySalesRankingByRankingIds(ids));
    }
}
